<template>
  <a-modal
    width='618px'
    title='交付物上传'
    cancelText="取消"
    okText="确定"
    :visible="visible"
    @ok="handleOk"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel">
    <commonUpload
      ref="commonUpload"
      :oid='stringOid'
      :multiple='false'
      :paramsVisible='false'
      @handleUpload='handleUpload'
      @handleRemove='handleRemove'/>
  </a-modal>
</template>
<script>
import {mapGetters} from 'vuex'
import commonUpload from '@/views/singleProject/fileSingle/el-common/comm-el-onUpload'
import copyACtion from '@/views/singleProject/fileSingle/el-common-js/copy'
let oId = JSON.parse(sessionStorage.getItem('oid'))
export default {
  mixins: [copyACtion],
  data() {
    return {
      stringOid: '',
      visible: false,
      fileArr: [],
      confirmLoading: false
    }
  },
  props: {
    sessionData: {
      type: Array,
      default: () => []
    },//存入的session
  },
  computed: {
    ...mapGetters({
      'fileSingleData': 'fileSingle'
    })
  },
  components: {
    commonUpload
  },
  created() {
    this.stringOid = oId + ''
  },
  methods: {
    /**
     * commonUpload 组件回调
     * 功能： props 选择交付物文件
     */
    handleUpload(info) {
      this.fileArr.push(info)
    },
    /**
     * commonUpload 组件回调
     * 功能：
     *      file 需要删除的文件
     *      fileList 删除之后的文件数组
     */
    handleRemove(file, fileList) {
      this.fileArr = fileList
    },
    /**
     * 确定按钮事件
     * 功能： 上传交付物
     */
    handleOk() {
      let rules = {
        '请选择交付物文件....': this.fileArr.length < 1
      }
      this.checkInUpFile({
        fileArr: this.fileArr,
        rules: rules,
        otherObj: {oid: this.sessionData[0].oid},
        callback: (res) => {
          if (res.code === 200) {
            this.visible = false
            this.$message.success('修改成功')
            //修改交付物会返回一个新的oid，要给session重新赋值
            let newFileSingleTableItem = {}
            newFileSingleTableItem.oid = res.data[0]
            newFileSingleTableItem.state = this.sessionData[0].state
            sessionStorage.setItem('fileSingleTableItem', JSON.stringify(newFileSingleTableItem))
            this.$emit('initTableData')
          } else {
            this.$message.error('操作失败！')
          }
        }
      })
    },
    /**
     * 取消按钮事件
     */
    handleCancel() {
      this.visible = false
      this.$refs.commonUpload.cancel()
    },
    /**
     * 开启弹窗
     * key 上级需要开启那个弹窗的key props上级tree选中的tree，propsArr 上级table选中的数据,
     * startF: 启动交付物独有参数
     */
    openModal(start) {
      this.visible = start
    },
  }
}
</script>
<style lang="less" scoped>
.width_410 {
  width: 410px;
}
</style>